//评论有关接口

import axios from "axios";
import { ElMessage } from "element-plus";
import { ref } from "vue";

//对某本书发表评论
export async function addBookCommentAPI(target_id, content ,proxy) {
   const formData = new FormData();
  console.log(target_id, content);
  try {
    formData.append("target_id", target_id);
    formData.append("type", "book");
    formData.append("content", content);
    const response = await proxy.$http.post("/api/comment/add",formData, {
      headers: { 
        'Content-Type': 'multipart/form-data'
      }
    });
    const res = response.data.data;
    console.log(res);
    const isSuccess = response.data.success;
    const message = response.data.message;
    if (isSuccess === false) {
      ElMessage.error(message);
    } else {
      // ElMessage.success("获取成功");
      return res;
    }
  } catch (error) {
    console.error(`Error fetching ${id} chapter:`, error);
    return [];
  }
}

